package com.example.service;

import com.example.entity.Grid;
import com.example.mapper.GridMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*  网格的逻辑层
**/
@Service
@RequiredArgsConstructor
public class GridService {

   private final GridMapper gridMapper;

   /**
   * 增
   **/
   public void add(Grid grid) {
       gridMapper.insert(grid);
   }

   /**
   * 删
   **/
   public void deleteById(Integer id) {
       gridMapper.deleteById(id);
   }

   /**
   * 批量删除
   **/
   public void deleteBatch(List<Integer> ids) {
       for (Integer id : ids) {
       gridMapper.deleteById(id);
       }
   }

   /**
   * 改
   **/
   public void updateById(Grid grid) {
       gridMapper.updateById(grid);
   }

   /**
   * 根据ID查询
   **/
   public Grid selectById(Integer id) {
       return gridMapper.selectById(id);
   }

   /**
   * 查询所有
   **/
   public List<Grid> selectAll(Grid grid) {
       return gridMapper.selectAll(grid);
   }

   /**
   * 分页查询
   **/
   public PageInfo<Grid> selectPage(Grid grid, Integer pageNum, Integer pageSize) {
       PageHelper.startPage(pageNum, pageSize);
       List<Grid> list = gridMapper.selectAll(grid);
       return PageInfo.of(list);
   }

}